package exercises.leetcode;

import java.util.Arrays;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年10月29日 时间: 19:14
 */
public class Jianxin_02 {
    public int[] analysisHistogram(int[] heights, int cnt) {
        Arrays.sort(heights);
        int resIndex = 0, min = Integer.MAX_VALUE;
        for (int i = cnt - 1, len = heights.length; i < len; i++)
            if (heights[i] - heights[i - cnt + 1] < min) {
                min = heights[i] - heights[i - cnt + 1];
                resIndex = i;
            }

        int[] res = new int[cnt];
        System.arraycopy(heights, resIndex - cnt + 1, res, 0, cnt);
        return res;
    }
}
